import 'package:flutter/material.dart';
import 'package:kasax_demos2/entry/data_posts_test.dart';
import 'package:kasax_demos2/entry/entrys.dart';
import 'package:kasax/utils/img_utils.dart';

class ListViewDemo3 extends StatefulWidget {
  const ListViewDemo3({Key? key}) : super(key: key);

  @override
  _ListViewDemo3State createState() => _ListViewDemo3State();
}

class _ListViewDemo3State extends State<ListViewDemo3> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("ListView3"),
      ),
      body: Container(
          margin: EdgeInsets.only(top: 15),
          child: ListView(
            children: PostsDatas.TEST_POSTS
                .map((e) => buildCardContainer(e, context))
                .toList(),
          )),
    );
  }

  Widget buildCardContainer(Posts entry, BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 10.0, right: 10.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ImageUtils.buildRoundImgByClip(entry.imageUrl),
          SizedBox(
            height: 15,
          ),
          Row(
            children: [
              CircleAvatar(
                backgroundColor: Colors.brown.shade800,
                backgroundImage: NetworkImage(entry.imageUrl),
              ),
              SizedBox(
                width: 10,
              ),
              Text(
                entry.author,
                style: Theme.of(context).textTheme.subtitle,
              ),
              Expanded(
                  child: Text(
                entry.title,
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
                textAlign: TextAlign.end,
                style: Theme.of(context).textTheme.bodyText2,
              ))
            ],
          )
        ],
      ),
    );
  }
}
